<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SafeInspect extends Model
{
    use HasFactory;

    protected $fillable = ['safe_id','project_id','type','content','person_id','days','correction_date','images','correction_id'];

    const POSTONLY = ['safe_id','project_id','type','content','person_id','days','correction_date','images','correction_id'];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function safe()
    {
        return $this->hasOne(Safe::class,'id','safe_id')->with('type')->select('id','floor','title','type_id');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','person_id')->select('id','name');
    }
}
